package com.china08.yxyapi.api.manage.sch.platform.live.lesson;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.live.YxyLiveLesson;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.live.YxyLiveLessonRepository;

@CrossOrigin
@RestController
public class LiveSchLessonInfoSaveController extends YxyApiBaseController {

    @Autowired
    private YxyLiveLessonRepository yxyLiveLessonRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/live/lesson/info/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        YxyLiveLesson yxyLiveLesson = yxyLiveLessonRepository.findById(reqModel.id);

        yxyLiveLesson.setName(reqModel.name);
        yxyLiveLesson.setSummary(reqModel.summary);
        yxyLiveLesson.setCover(reqModel.cover);
        yxyLiveLesson.setTeacherSchoolId(reqModel.schoolId);
        yxyLiveLesson.setTeacherSchoolNick(reqModel.schoolName);
        yxyLiveLesson.setTeacherMobile(reqModel.phone);
        yxyLiveLesson.setCatalogId1(reqModel.catalogId1);
        yxyLiveLesson.setCatalogId2(reqModel.catalogId2);
        yxyLiveLesson.setCatalogId3(reqModel.catalogId3);
        yxyLiveLesson.setLiveType(reqModel.type);

        yxyLiveLessonRepository.save(yxyLiveLesson);

        RespModel model = new RespModel();

        model.setMessage("修改成功");
        return model;
    }

    public static class ReqModel extends YxyApiReqModel {
        public String id;

        public String name;

        public String summary;

        public String cover;

        public String schoolId;

        public String schoolName;

        public String phone;

        public String userName;

        public String catalogId1;

        public String catalogId2;

        public String catalogId3;

        public Integer type;
    }

    public static class RespModel extends YxyApiRespModel {

    }

}
